﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using LinFen;
using SubSonic;

public partial class webUserControl_PointsTimeUp : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Cookies aCookies=new Cookies();
        if(aCookies.getCookies("cisType").ToString()!="3")
        {
            GridView2.Columns[8].Visible = false;
            GridView2.Columns[12].Visible = false;
        }
    }
    protected void GridView2_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "shifang")
        {
            int oID = int.Parse(e.CommandArgument.ToString());
            StoredProcedure sp = new StoredProcedure("sp_ExcuteOrderSingle");
            sp.Command.AddParameter("@oID", oID);
            sp.Execute();
            Query q = new Query("orderinfo");
            q.AddWhere("ID", oID);
            IDataReader dr = q.ExecuteReader();
            if (dr.Read())
            {
                int NumMale = int.Parse(dr[3].ToString());
                int NumFeMale = int.Parse(dr[4].ToString());
                int NumHongGan = int.Parse(dr[5].ToString());
                int NumBaoJian = int.Parse(dr[6].ToString());
                int NumQiTa = int.Parse(dr[7].ToString());
                SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["LinFen"].ConnectionString);
                SqlCommand cmd = new SqlCommand();
                cmd.CommandType = CommandType.Text;
                cmd.Connection = conn;
                cmd.CommandText = "update customerinfo set isOKPoint = isOKPoint -" +
                                  (NumQiTa + NumMale + NumHongGan + NumFeMale + NumBaoJian) + " where id=" + dr[1];
                conn.Open();
                cmd.ExecuteNonQuery();
                OrderInfo.Delete("ID", oID);
                conn.Close();
            }
            GridView2.DataBind();
            //Response.Redirect(Request.Url.ToString());
        }
    }
}
